package piwan;

import java.io.IOException;
import java.io.Writer;
import java.util.Scanner;

public class ResourceType {
	
	public ResourceType() {
		name="<unnamed>";
		icon="";
		id = -1;
		combo = -1;
		soldiers = -1;
	}
	
	public ResourceType set(String newName, int newId, int newCombo, int newSoldiers, String newIcon) {
		name = newName;
		id = newId;
		combo = newCombo;
		soldiers = newSoldiers;
		icon = newIcon;
		return this;
	}
	
	public int getSoldiersFor(int n) { assert(combo!=0); return n/combo * soldiers; }
	
	public String getIconFile() { return icon; }
	
	public void setId( int newId ) {
		id = newId;
	}
	
	public ResourceType clone() {
		return (new ResourceType()).set(name, id, combo, soldiers,icon);
	}
	
	public String getName() {
		return name;
	}
	
	public int getCombo() {
		return combo;
	}
	
	public int getSoldiersPerCombo() {
		return soldiers;
	}
	
	public int getId() {
		return id;
	}
	
	public void writeText( Writer writer ) throws IOException {
		writer.write(name + " " + combo + " " + soldiers + " " + icon + "\n");
	}
	
	public void readText( Scanner scan ) throws IOException {
		name = scan.next();
		combo = scan.nextInt();
		soldiers = scan.nextInt();
		icon = scan.next();
	}
	
	private String name;
	private String icon;
	private int id,combo;
	private int soldiers;
	
}
